// $Id$
// Licensed under Apache License Version 2.0
// See: http://www.apache.org/licenses/LICENSE-2.0.html
package de.servicezombie.tests.mongo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.MongoTemplate;

public class MongoTestSupport {
	
	private static final Logger log = LoggerFactory.getLogger(MongoTestSupport.class);
	
	private MongoTemplate mongoTemplate;
	
	public void setMongoTemplate(MongoTemplate mongoTemplate) {
		this.mongoTemplate = mongoTemplate;
	}

	/**
	 * connect to current configured database and remove every document from every collection
	 */
	public void rebuildDatabase(Class<?>... typesToBeDropped) {
		for(Class<?> type : typesToBeDropped) {			
			if (log.isInfoEnabled()) {
				log.info("rebuildDatabase: drop collection for " + type);
			}
			mongoTemplate.dropCollection(type);
		}
	}

}
